package com.heu.blood.autologous.controller;

import com.heu.blood.application.exception.ApplicationExceptionEnum;
import com.heu.blood.autologous.entity.BloodApplicationItemAutologousEntity;
import com.heu.blood.autologous.service.BloodApplicationItemAutologousService;
import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import com.heu.blood.globalExceptionHandler.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author lyj
 * @email lyj@heu.com
 * @date 2024-11-27 17:50:46
 */
@RestController
@RequestMapping("autologous/bloodapplicationitemautologous")
public class BloodApplicationItemAutologousController {
    @Autowired
    private BloodApplicationItemAutologousService bloodApplicationItemAutologousService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "自体血模块", operate = "获取自体血申请项目列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodApplicationItemAutologousService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "自体血模块", operate = "按照ID获取指定的自体血申请信息")
    public R info(@PathVariable("id") Long id){
		BloodApplicationItemAutologousEntity bloodApplicationItemAutologous = bloodApplicationItemAutologousService.getById(id);

        return R.ok().put("bloodApplicationItemAutologous", bloodApplicationItemAutologous);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ControllerLogAnnotation(module = "自体血模块", operate = "保存自体血申请项目信息")
    public R save(@RequestBody BloodApplicationItemAutologousEntity bloodApplicationItemAutologous){
		bloodApplicationItemAutologousService.save(bloodApplicationItemAutologous);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "自体血模块", operate = "修改自体血申请信息")
    public R update(@RequestBody BloodApplicationItemAutologousEntity bloodApplicationItemAutologous){
		bloodApplicationItemAutologousService.updateById(bloodApplicationItemAutologous);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "自体血模块", operate = "批量逻辑删除自体血申请信息")
    public R delete(@RequestBody Long[] ids){
		bloodApplicationItemAutologousService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

   /* @RequestMapping("addInventory")
    @ControllerLogAnnotation(module = "自体血模块", operate = "采血后修改申请项状态为已采血并生成库存记录")
    public R addInventory(@RequestBody BloodApplicationItemAutologousEntity bloodApplicationItemAutologous){
        bloodApplicationItemAutologousService.addInventory(bloodApplicationItemAutologous);
       /* if(flag == 1){
            return R.ok();
        }else if(flag == 0){
            throw new MyException(ApplicationExceptionEnum.ILLEGAL_PARAMS);
        }
        return R.ok();
    }*/

}
